package org.subside.MQ.rabbitmq.RoutingModel;

import com.rabbitmq.client.*;
import org.subside.MQ.rabbitmq.config.ConnectionUtil;

import java.io.IOException;


public class ConsumerRoutingError {
 
    private static final String EXCHANGE_NAME = "exchange_routing";
 
    private static final String ERROR_QUEUE = "errorQueue";
    private static final String ROUTINGKEY_ERROR = "errorKey";


    public static void main(String[] args) throws Exception {
        Connection connection =  ConnectionUtil.getConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, "direct");
            channel.queueDeclare(ERROR_QUEUE, false, false, true, null);
            //将交换器与队列通过路由键绑定
            channel.queueBind(ERROR_QUEUE, EXCHANGE_NAME, ROUTINGKEY_ERROR);
            DeliverCallback callback = (String consumerTag, Delivery message) -> {
                String msg = new String(message.getBody(), "UTF-8");
                System.out.println(msg);
            };
            System.out.println("消费者error正在监听。。。。");
            channel.basicConsume(ERROR_QUEUE, true, callback, (consumerTag) -> {
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}